// FetionWindow.cpp
// Heihaier <admin@heihaier.org>
// http://www.heihaier.org

#include "FetionWindow.h"
#include "FetionLoginBox.h"

FetionWindow::FetionWindow()
{
	m_pFetionStatusIcon = NULL;

	set_title("Linux Fetion");
	set_icon_from_file("./misc/fetion.png");
	set_default_size(220, 580);

	FetionLoginBox * pFetionLoginBox = Gtk::manage(new FetionLoginBox);
	add(*pFetionLoginBox);

	// connect signal_system_msg callback function
	signal_system_msg.connect(sigc::mem_fun(this, &FetionWindow::on_system_msg));
	// connect signal_login_ok callback function
	signal_login_ok.connect(sigc::mem_fun(this, &FetionWindow::on_login_ok));

	set_border_width(2);
}

FetionWindow::~FetionWindow()
{
	if(m_pFetionStatusIcon)
	  delete m_pFetionStatusIcon;
}

void FetionWindow::on_system_msg(int message, WPARAM wParam, LPARAM lParam)
{
	Fetion_MSG * pFetionMSG = NULL;

	switch(message)
	{
	case FX_NEW_MESSAGE:
		pFetionMSG = fx_get_msg((long)lParam);
		if(pFetionMSG)
		{
			fx_destroy_msg(pFetionMSG);
		}
		break;
	case FX_NEW_QUN_MESSAGE:
		break;
	case FX_SYS_MESSAGE:
		break;
	case FX_UNDGE_MESSAGE:
		break;
	case FX_SMS_OK:
		break;
	case FX_SMS_FAIL:
		break;
	case FX_SMS_TIMEOUT:
		break;
	case FX_SMS_UNKOWN_ERROR:
		break;
	case FX_SMS_FAIL_LIMIT:
		break;
	case FX_DIA_BG_TRYING:
		break;
	case FX_DIA_BG_OK:
		break;
	case FX_DIA_BG_FAIL:
		break;
	case FX_DIA_SEND_OK:
		break;
	case FX_DIA_SEND_FAIL:
		break;
	case FX_DIA_SEND_TIMEOUT:
		break;
	case FX_DIA_UNKOWN_ERROR:
		break;
	case FX_STATUS_UNSET:
		break;
	case FX_STATUS_ONLINE:
		break;
	case FX_STATUS_BUSY:
		break;
	case FX_STATUS_OFFLINE:
		break;
	case FX_STATUS_AWAY:
		break;
	case FX_STATUS_MEETING:
		break;
	case FX_STATUS_PHONE:
		break;
	case FX_STATUS_DINNER:
		break;
	case FX_STATUS_EXTENDED_AWAY:
		break;
	case FX_STATUS_NUM_PRIMITIVES:
		break;
	case FX_STATUS_WAITING_AUTH:
		break;
	case FX_STATUS_REFUSE:
		break;
	case FX_STATUS_BLACK:
		break;
	case FX_STATUS_MOBILE:
		break;
	case FX_STATUS_SMSEXTENED:
		break;
	case FX_ACCOUNT_UPDATA_OK:
		break;
	case FX_ADD_GROUP_OK:
		break;
	case FX_ADD_GROUP_FAIL:
		break;
	case FX_ADD_GROUP_TIMEOUT:
		break;
	case FX_DEL_GROUP_OK:
		break;
	case FX_DEL_GROUP_FAIL:
		break;
	case FX_DEL_GROUP_TIMEOUT:
		break;
	case FX_RENAME_GROUP_OK:
		break;
	case FX_RENAME_GROUP_FAIL:
		break;
	case FX_RENAME_GROUP_TIMEOUT:
		break;
	case FX_SET_BUDDY_INFO_OK:
		break;
	case FX_SET_BUDDY_INFO_FAIL:
		break;
	case FX_SET_BUDDY_INFO_TIMEOUT:
		break;
	case FX_ADDACCOUNT_APP:
		break;
	case FX_ADD_BUDDY_OK:
		break;
	case FX_SYS_ERR_NETWORK:
		break;
	case FX_SYS_DEREGISTERED:
		break;
	case FX_SET_STATE_OK:
		break;
	case FX_SET_STATE_FAIL:
		break;
	case FX_SET_STATE_TIMEOUT:
		break;
	case FX_SET_IMPRESA_OK:
		break;
	case FX_SET_IMPRESA_FAIL:
		break;
	case FX_SET_NICKNAME_OK:
		break;
	case FX_SET_NICKNAME_FAIL:
		break;
	case FX_SET_REFUSE_SMS_DAY_OK:
		break;
	case FX_SET_REFUSE_SMS_DAY_FAIL:
		break;
	case FX_ADD_BLACKLIST_OK:
		break;
	case FX_ADD_BLACKLIST_FAIL:
		break;
	case FX_ADD_BLACKLIST_TIMEOUT:
		break;
	case FX_REMOVE_BLACKLIST_OK:
		break;
	case FX_REMOVE_BLACKLIST_FAIL:
		break;
	case FX_REMOVE_BLACKLIST_TIMEOUT:
		break;
	case FX_DEL_BUDDY_OK:
		break;
	case FX_DEL_BUDDY_FAIL:
		break;
	case FX_DEL_BUDDY_TIMEOUT:
		break;
	case FX_MOVE_GROUP_OK:
		break;
	case FX_MOVE_GROUP_FAIL:
		break;
	case FX_RECEIVE_FILE:
		break;
	case FX_CURRENT_VERSION:
		break;
	case FX_GET_QUNLIST_OK:
		break;
	case FX_GET_QUNLIST_FAIL:
		break;
	case FX_QUN_GP_OK:
		break;
	case FX_QUN_SEND_OK:
		break;
	case FX_QUN_SEND_TIMEOUT:
		break;
	case FX_QUN_SEND_FAIL:
		break;
	case FX_QUN_SMS_OK:
		break;
	case FX_QUN_SMS_TIMEOUT:
		break;
	case FX_QUN_SMS_FAIL:
		break;
	case FX_QUN_SMS_FAIL_LIMIT:
		break;
	}
}

void FetionWindow::on_login_ok()
{
	int status = 10;
	
	switch(fx_get_user_state())
	{
	case FX_STATUS_ONLINE:		// Online
		status = 10;
		break;
	case FX_STATUS_BUSY:		// Busy
		status = 20;
		break;
	case FX_STATUS_AWAY:		// Away
		status = 50;
		break;
	case FX_STATUS_OFFLINE:		// Hide
		status = 30;
		break;
	}

	m_pFetionStatusIcon = new FetionStatusIcon(status);
	remove();	// remove fetion login box
	// new fetion main box and add to fetion window
	m_pFetionMainBox = manage(new FetionMainBox());
	add(*m_pFetionMainBox);
}
